package com.yugao.fintech.antelope.gateway.remote;

import com.yugao.fintech.framework.assistant.utils.exception.BizException;
import com.yugao.fintech.framework.core.response.Resp;
import com.yugao.fintech.framework.core.response.RetOps;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Future;

@Service
public class AuthApi {
    @Autowired
    private AuthRemote service;

    @Async
    public Future<Map<String, List<String>>> listClientPermission(String clientId) {
        Resp<Map<String, List<String>>> resp = service.listClientPermission(clientId);
        RetOps.of(resp).assertSuccess(e -> new BizException(e.getCode(), e.getMsg()));

        Map<String, List<String>> data = Optional.ofNullable(resp.getData()).orElse(new ConcurrentHashMap<>());
        return new AsyncResult<>(data);
    }
}
